﻿
#region 引用
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

using SiteCommon;
using BLL;
using Model;
#endregion

public partial class CustomerManage_RegManage : System.Web.UI.Page
{
    #region 字段
    private string _callPhone = "";
    #endregion

    #region 页面初始化程序
    /// <summary>
    /// 页面初始化程序
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        lblError.Text = "";

        this._callPhone = SiteCommon.Common.GetString(Request.QueryString["CallPhone"]);

        if (!this.IsPostBack)
        {
            Model.V_CUSTOMER user;
            UserInfoBL mInter = new UserInfoBL();
            string ret = mInter.GetUserByCallPhone(this._callPhone, out user);

            if (ret == Model.Config.NOTEXISTSDATA
                && user == null)
            {
                lblError.Text = "此客户尚未注册，"
                    + "<a href=\"../CustomerArchives/AddVIP.aspx?isorder=1\" target=\"_blank\">"
                    + "点击这里注册"
                    + "</a>";
            }
            else if (ret == Model.Config.SUCCESS
                && user != null)
            {
                txtEmail.Text = user.EMAIL;
                this.GetUserInfo(" dm='"+user.DM+"'");
            }
            else if(ret != Model.Config.SUCCESS)
            {
                lblError.Text = ret;
            }
        }
    }
    #endregion

    #region 绑定用户信息
    /// <summary>
    /// 绑定用户信息
    /// </summary>
    /// <param name="where"></param>
    private void GetUserInfo(string where)
    {
        UserInfoBL mInter = new UserInfoBL();
        string username = mInter.GetUserNameByEmail(where);
        if (username == "")
        {
            lblError.Text = "未获取到用户帐号";
            rpRegInfo.Visible = false;
        }
        else
        {
            DataSet ds = new BLL.V_CUSTOMER().GetCustomerInfo(username);
            if (ds != null)
            {
                rpRegInfo.Visible = true;
                rpRegInfo.DataSource = ds;
                rpRegInfo.DataBind();
            }
            else
            {
                lblError.Text = "未获取到用户信息";
                rpRegInfo.Visible = false;
            }
        }
    }
    #endregion

    #region 根据邮箱查询用户注册信息
    /// <summary>
    /// 根据邮箱查询用户注册信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string where = "1=1";
        string usercode = Tbx_usercode.Text.Trim();
        if (usercode != "")
        {
            where += " and DM ='" + usercode + "'";
        }
        string Tel = Tbx_Tel.Text.Trim();
        if (Tel.Length > 0)
        {
            where += " and REPLACE(DH,'-','')='" + Tel + "'";
        }
        string mobile = Tbx_Mobile.Text.Trim();
        if (mobile.Length > 0)
        {
            where += " and sj='" + mobile + "'";
        }
        string email = txtEmail.Text.Trim();
        if (email.Length > 0)
        {
            if (!CommonCheck.CheckEmail(email))
            {
                lblError.Text = "您输入的邮箱错误";
                return;
            }
            else
            {
                where += " and Email='" + email + "'";
            }
        }


        this.GetUserInfo(where);
    }
    #endregion
}
